/**
 * @(#)ApkConfigController.java 2017年03月1日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.http.client.utils.HttpClientUtils;
import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.domian.SimulatorTaskIssueLog;
import org.jsbd.boss.service.ISimulatorTaskIssueLogService;
import org.jsbd.boss.util.AndroidBase64;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;

@Controller
@RequestMapping("/simulatorTaskIssueLog")
public class SimulatorTaskIssueLogController {

	public static final Logger logger = LoggerFactory.getLogger(SimulatorTaskIssueLogController.class);

	@Autowired
	private ISimulatorTaskIssueLogService simulatorTaskIssueLogService;

	@RequestMapping(value = "getTotal")
	@ResponseBody
	public Integer getTotal(SimulatorTaskIssueLog log) {
		return simulatorTaskIssueLogService.getListCount(log);
	}

	@RequestMapping(value = "getList")
	@ResponseBody
	public List<SimulatorTaskIssueLog> getList(SimulatorTaskIssueLog log) {
		
		if(log.getTaskType()!=null){
			String searchWord = "\"taskType\":"+log.getTaskType();
			if(log.getKeywords()==null){
				List<String> list = new ArrayList<>();
				list.add(searchWord);
				log.setKeywords(list);
			}else {
				log.getKeywords().add(searchWord);
			}
		}
		
		List<SimulatorTaskIssueLog> list = simulatorTaskIssueLogService.getList(log);
		for (SimulatorTaskIssueLog issueLog : list) {
			
			issueLog.setTaskContent(AndroidBase64.encode(issueLog.getTaskContent().getBytes()));
			
//			try {
//				issueLog.setTaskContent(URLEncoder.encode(issueLog.getTaskContent(), "UTF-8"));
//				
//				smsVo.setMessage(AndroidBase64.encode(message.getBytes()));
//			} catch (UnsupportedEncodingException e) {
//				e.printStackTrace();
//			}
		}
		return list;
	}

	@RequestMapping(value = "help")
	public void help(HttpServletResponse response) {
		StringBuilder sb = new StringBuilder();
		sb.append("currentDate=表日期").append("\r\n");
		sb.append("keywords=关键字，可多关键字").append("\r\n");
		sb.append("先查询数据总量，例如： ").append("\r\n");
		sb.append("/simulatorTaskIssueLog/getTotal?keywords=AA&keywords=bb&currentDate=20180820").append("\r\n");
		sb.append("然后分页查数据查询数据 ").append("\r\n");
		sb.append("参数 pageIndex=从第几条开始返回 ").append("\r\n");
		sb.append("参数 pageCount=一次返回数据条数 ").append("\r\n");
		sb.append(
				"/simulatorTaskIssueLog/getList?keywords=AA&keywords=bb&currentDate=20180820&pageIndex=0&pageCount=5");

		ResponseUtils.renderText(response, sb.toString());
	}

	 private static final int COUNT_BITS = Integer.SIZE - 3;
	    private static final int CAPACITY   = (1 << COUNT_BITS) - 1;

	    // runState is stored in the high-order bits
	    private static final int RUNNING    = -1 << COUNT_BITS;
	    private static final int SHUTDOWN   =  0 << COUNT_BITS;
	    private static final int STOP       =  1 << COUNT_BITS;
	    private static final int TIDYING    =  2 << COUNT_BITS;
	    private static final int TERMINATED =  3 << COUNT_BITS;
	    
	public static void main(String[] args) {
		
		String searchWord = "\"taskType\":"+3;
		
		System.out.println(searchWord);
		
		System.out.println(-1<<29);
		
		
		
		    System.out.println(RUNNING);
		    System.out.println(SHUTDOWN);
		    System.out.println(STOP);
		    System.out.println(TIDYING);
		    System.out.println(TERMINATED);
		    
			int i = 0;
			outer: 
			while (true) {
			System.out.println("Outer while loop");
			while (true) {
				i++;
				System.out.println("i = " + i);
				if (i == 1) {
					System.out.println("continue");
					continue;
				}
				if (i == 3) {
					System.out.println("continue outer");
					continue outer;
				}
				if (i == 5) {
					System.out.println("break");
					break;
				}
				if (i == 7) {
					System.out.println("break outer");
					break outer;
				}
			}
		}

	}

}
